#用类实现斐波那契数列的运算（编写自定义迭代器）
#迭代器
#__iter__  方法返回自身
#   return self
#__next__  返回下一个值
#最后实例化成一个迭代器对象 斐波那契数列

#0,1,1,2,3,5,8,13,21,34
# from itertools import islice
# def fib():
#     prev,curr = 0,1
#     while True:
#         yield curr
#         prev,curr = curr,curr + prev

class Fibonacci():
    def __init__(self,len):
        self.len = len
        self.num1 = 0
        self.num2 = 1

    def __iter__(self):
        return self

    def __next__(self):
        while self.len:
            result = self.num1
            self.num1,self.num2 = self.num2,self.num1+self.num2
            self.len -= 1
            return result
        raise StopIteration
for i in Fibonacci(20):
    print(i,end=" ")














